package test;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharsetUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.lkl.entity.AddressVO;
import com.lkl.utils.FileUtils;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.io.entity.EntityUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException, ParseException {
//        //创建连接池管理器
//        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
//        CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).build();
//        //基础网页
//        HttpGet httpGet = new HttpGet("http://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/index.html");
//        httpGet.setHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36");
//        CloseableHttpResponse response = httpClient.execute(httpGet);
//        if( response.getCode() == 200){
//            String content = EntityUtils.toString(response.getEntity(), "utf8");
//            System.out.println(content.length());
//        }
//        response.close();
        AddressVO addressVO = new AddressVO("110000", "北京市", "100000");
        System.out.println(addressVO);
        System.out.println(JSONObject.toJSONString(addressVO, SerializerFeature.WriteMapNullValue));
        StringBuilder path = new StringBuilder();
        path.append(FileUtils.filePath)
                .append("/")
                .append("北京市")  //北京市
                .append("/")                      // /
                .append("北京市")  // 北京市
                .append("城市数据/")               // 城市数据/
                .append("市辖（区）")       //  市辖区
                .append("-区-镇-村-三级.json");                 // -区-镇-村-三级.json
        List<String> collect1 = new ArrayList<>();
        //获取子数据并转换为json
        collect1.add(JSONObject.toJSONString(addressVO, SerializerFeature.WriteMapNullValue));
        FileUtil.writeLines(collect1, path.toString(), CharsetUtil.CHARSET_UTF_8, true);

    }
}
